<template>
  <div class="app-container">
    <!-- 添加或修改会员管理对话框 -->
    <el-dialog title="提现审批" :visible.sync="visible" width="40%" append-to-body :close-on-click-modal="false" @close="dialogClose">
      <div style="text-align: center;font-size: 18px;line-height: 24px;">
        <div>用户：{{ userId }}({{ userName }})</div>
        <div>提现：<span style="font-weight: bold;color： #f00">￥{{ withdrawApplication }}</span>元</div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="dialogAgree">同意提现</el-button>
        <el-button size="mini" @click="dialogRefuse">拒绝</el-button>
      </div>
    </el-dialog>

    <!-- 同意提现 -->
    <el-dialog title="提现审批" :visible.sync="agreeDialogVisible" width="40%" append-to-body :close-on-click-modal="false" @close="agreeDialogVisible = false">
      <div style="text-align: center;font-size: 18px;line-height: 24px;">
        <div>提现二次确认</div>
        <div>用户：{{ userId }}({{ userName }})</div>
        <div>提现：<span style="font-weight: bold;color： #f00">￥{{ withdrawApplication }}</span>元</div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="handleRemit">确认打款</el-button>
        <el-button size="mini" @click="agreeDialogVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <!-- 拒绝 -->
    <el-dialog title="提现审批" :visible.sync="refuseDialogVisible" width="40%" append-to-body :close-on-click-modal="false" @close="refuseDialogVisible = false">
      <el-form ref="form" :model="form">
        <el-form-item label="拒绝理由：" prop="errorMsg">
          <el-input v-model="form.errorMsg" placeholder="请输入" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="handleRefuse">确认拒绝</el-button>
        <el-button size="mini" @click="refuseDialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import { checkWithdrawalAudit } from '@/api/shuiyin/shuiyin.js'
export default {
  props: {
    userId: {
      type: String,
      default: ''
    },
    userName: {
      type: String,
      default: ''
    },
    withdrawId: {
      type: [String, Number],
      default: ''
    },
    withdrawApplication: {
      type: Number,
      default: 0
    },
    dialogVisibleFlag: {
      default: false
    }
  },
  data() {
    return {
      visible: false,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 租户管理表格数据
      tenantList: [], 
      // 查询参数
      queryParams: {
        userId: null,
        pageNum: 1,
        pageSize: 10,
      },
      form: {
        errorMsg: ''
      },
      agreeDialogVisible: false,
      refuseDialogVisible: false
    };
  },
  watch: {
    dialogVisibleFlag() {
      this.visible = this.dialogVisibleFlag;
      if (this.visible) {
        this.form.employeeRetain = this.employeeRetain;
      }
    }
  },
  methods: {
    dialogClose() {
      this.$emit("update:dialogVisibleFlag", false)
    },
    // 同意提现
    dialogAgree() {
      this.agreeDialogVisible = true;
    },
    // 拒绝
    dialogRefuse() {
      this.refuseDialogVisible = true;
    },
    // 确认修改
    handleRemit() {
      const params = {
        withdrawId: this.withdrawId,
        checkStatus: 1
      }
      checkWithdrawalAudit(params).then(response => {
        this.$modal.msgSuccess("审批成功");
        this.dialogVisible = false;
        this.dialogClose();
      })
    },
    handleRefuse() {
      const params = {
        withdrawId: this.withdrawId,
        checkStatus: 2,
        errorMsg: this.form.errorMsg
      }
      checkWithdrawalAudit(params).then(response => {
        this.$modal.msgSuccess("审批成功");
        this.dialogVisible = false;
        this.dialogClose();
      })
    }
  }
};
</script>